﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Management.Automation;
using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Desktop;

namespace BO.Management.PowerShell
{
    [Cmdlet(VerbsCommon.Get, "FolderFullPath")]
    public class GetFolderFullPath : Cmdlet
    {
        #region "Private members"
        private System.Diagnostics.Stopwatch w;
        #endregion

        #region "Public members"
        [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
        [ValidateNotNullOrEmpty]
        public Folder InputObject { get; set; }

        #endregion

        /// <summary>
        /// End  processing treatments
        /// </summary>
        protected override void EndProcessing()
        {
            //if (this.Folder != null) this.Folder.Dispose();
            base.EndProcessing();
            w.Stop();
            WriteVerbose(String.Format("End {0} in {1}", this.GetType().Name, w.Elapsed));
        }
        
        /// <summary>
        /// Start Begin processing
        /// </summary>
        protected override void BeginProcessing()
        {
            WriteVerbose(String.Format("Start {0}", this.GetType().Name));
            w = new System.Diagnostics.Stopwatch();
            w.Start();
            base.BeginProcessing();
        }

        /// <summary>
        /// Expand the inputObjects to display full path of the object
        /// </summary>
        protected override void ProcessRecord()
        {
            if (this.InputObject != null)
            {
                WriteVerbose(String.Format("Extract Full path for the Folder {0}", this.InputObject.Title));
                this.WriteObject(ContentFolderProvider.GetFullPath(this.InputObject));
            }
        }

    }
}
